namespace Microsoft.ServiceModel.Samples.Discovery.Protocol
{
    using System;
    using System.Xml;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    
    public class ResolveRequest : FindRequest
    {
        Resolve resolve;
    
        internal ResolveRequest(Resolve resolve, OperationContext opContext)
            : base(opContext)
        {
            this.resolve = resolve;
        }

        public Resolve Resolve
        {
            get
            {
                return this.resolve;
            }
        }

        /*
        public void Reply(ResolveMatch resolveMatch)
        {
            EnsureResponseChannel();

            ResolveMatches matches = new ResolveMatches();
            matches.Items = new ResolveMatch[1];
            matches.Items[0] = resolveMatch;

            Reply(matches);
        }
         */

        public void Reply(ServiceProperties properties)
        {
            EnsureResponseChannel();

            ResolveMatches matches = new ResolveMatches();
            matches.Items = new ResolveMatch[1];
            matches.Items[0] = ResolveMatch.FromServiceProperties(properties);

            Reply(matches);
        }

        public void Reply(ResolveMatches resolveMatches)
        {
            EnsureResponseChannel();

            using (new OperationContextScope((IContextChannel)ResponseChannel))
            {
                AddOutgoingMessageHeaders();

                ResolveMatchesMessage message = new ResolveMatchesMessage();
                message.ResolveMatches = resolveMatches;
                ResponseChannel.ResolveMatchOperation(message);
            }
        }
    }
}
